package cn.edu.nit.sys.controller;

import cn.edu.nit.sys.entity.Employee;
import cn.edu.nit.sys.service.EmployeeService;
import cn.edu.nit.sys.utils.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author xiaobai
 * @Date 2022/9/26 21:35
 * @Version 1.0.0
 */
@RestController
@Slf4j
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @GetMapping
    public R getList(Page<Employee> page, String name, Integer type) {
        return employeeService.getList(page, name, type);
    }

    @GetMapping("/type")
    public R getType() {
        return employeeService.getType();
    }

    @PostMapping
    public R addEmployee(@RequestBody Employee employee) {
        log.info("入参{}", employee);
        return employeeService.addEmployee(employee);
    }

    @PutMapping
    public R updateEmployee(@RequestBody Employee employee) {
        log.info("入参{}", employee);
        return employeeService.updateEmployee(employee);
    }

    @DeleteMapping("/{id}")
    public R delEmployee(@PathVariable("id")Long id) {
        log.info("入参{}", id);
        return employeeService.delEmployee(id);
    }

    @GetMapping("/repair")
    public R getEmpByType() {
        return employeeService.getEmpByType();
    }
}
